package aes

import (
	"crypto/aes"
	"fmt"
	"gitee.com/gcom/gbox/crypto"
)

type aesCrypt struct {
	crypto.CipherCrypt
}

func NewAESCrypt(key []byte) *aesCrypt {
	block, err := aes.NewCipher(key)
	if err != nil {
		panic(err)
	}
	return &aesCrypt{CipherCrypt: crypto.CipherCrypt{Block: block}}
}

func NewAESCryptWithDecode(key string, keyDataType crypto.Encode) *aesCrypt {
	data, err := crypto.DecodeString(key, keyDataType)
	if err != nil {
		panic(fmt.Sprintf("gocrypt decode key error : %v ", err))
	}
	return NewAESCrypt(data)
}
